import { ACTION_USER } from '../action';
import { User } from '@api';

const UserStore = {
	namespaced: true,
	state: {
		userInfo: null,
	},
	getters: {
		getUserInfo: state => state.userInfo,
	},
	mutations: {
		[ACTION_USER.SET_USERINFO](state, payload) {
			state.userInfo = payload;
		},
	},
	actions: {
		signIn({ commit }, param) {
			return User.signIn(param)
				.then(() => {
					commit(ACTION_USER.SET_USERINFO, param);
					return '123456';
				});
		},
		signout({ commit }) {
			return User.signout()
				.then(() => {
					commit(ACTION_USER.SET_USERINFO, null);
				});
		},
	},
};

export default UserStore;
